package com.linewow.xhyy.nihaonew.fragment;

import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

//import com.linewow.xhyy.hrxb.fragment.ConversationListFragment;
import com.linewow.xhyy.hrxb.message.HrXbMessageEvent;
import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.activity.account.LoginActivity;
import com.linewow.xhyy.nihaonew.application.NiHaoApp;
import com.linewow.xhyy.nihaonew.base.ListBaseFragmentNormal;

import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

/**
 * Created by LXR on 2016/8/23.
 *身份的处理 在父类中决定
 *
 */
public class MessageFragment extends ListBaseFragmentNormal {
    private FragmentManager manager;
    private TestConversationFragment conversationFragment;
    private String TAG="MessageFragment";
    @Override
    protected void setUpView() {
        super.setUpView();
        manager=getFragmentManager();
        manager=getFragmentManager();
        rightImg.setVisibility(View.GONE);
        leftImg.setVisibility(View.GONE);
        midTv.setText(getString(R.string.navigation_message));
        initFragment();
        midTv.setClickable(true);
        midTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initFragment();
            }
        });
        FrameLayout frameLayout=new FrameLayout(getActivity());
        frameLayout.setId(getResources().getInteger(R.integer.message_fragment_id));
        listBaseContent.addView(frameLayout);
    }

    @Override
    public void onResume() {
        super.onResume();
        setLogin(NiHaoApp.flag);//写在父类中还需要  在这儿离再设置一次  否则不显示fragment
    }

    private void initFragment() {

//        manager.beginTransaction().add(R.id.list_base_content,conversationFragment).commit();

        conversationFragment=new TestConversationFragment();
        manager.beginTransaction().add(getResources().getInteger(R.integer.message_fragment_id),conversationFragment).commit();
    }

    @Override
    protected void initList() {
        super.initList();
        listener=new ListBaseListener() {
            @Override
            public void onLoginListener() {
                Intent intent=new Intent(MessageFragment.this.getActivity(), LoginActivity.class);
                startActivity(intent);
            }
            @Override
            public void onRetryListener() {

            }
        };
        EventBus.getDefault().register(this);

    }

    @Subscriber(tag = "MessageFragment",mode = ThreadMode.MAIN)
    public void updataFragment(HrXbMessageEvent hrXbMessageEvent){
        Log.e(TAG,"刷新了");
//        conversationFragment.refresh();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
